package com.power.sifa.approve.model;


import com.alibaba.fastjson.JSON;
import com.aventrix.jnanoid.jnanoid.NanoIdUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.plf.core.common.annotations.FieldEnumText;
import com.plf.core.common.domain.BaseModel;
import com.power.sifa.approve.model.enumeration.Tp_lictype;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
*  文书云签章实体类
*/

@Entity
@ApiModel(value="文书云签章")
@Data
@Table(name="Cloud_sign_license",schema="sfapprove")
@AllArgsConstructor
@NoArgsConstructor
@Builder
@EqualsAndHashCode(callSuper = false)
//@IdClass(Cloud_sign_license.Cloud_sign_licensePK.class) 用于复合组件
public class Cloud_sign_license extends BaseModel implements Serializable {

	private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_cloud_sign_license")
    @SequenceGenerator(name = "seq_cloud_sign_license", sequenceName = "SEQ_CLOUD_SIGN_LICENSE", allocationSize = 1)
    @Setter(AccessLevel.NONE)
    @ApiModelProperty(value = "id")
    private Integer id;

    @ApiModelProperty(value = "文书编号")
    private String cert_no;

    @ApiModelProperty(value = "文书类型")
    private String lictypeid;

    @ApiModelProperty(value = "联号")
    private Integer pageindex;

    @ApiModelProperty(value = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date createtime;

    @ApiModelProperty(value = "处理时间")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date exectime;

    @ApiModelProperty(value = "文书路径")
    private String filepath;

    @ApiModelProperty(value = "处理结果")
    private String result;

    @ApiModelProperty(value = "印章配置")
    private String sealinfo;


    public Map<String, Object> parseMap() {
        Map<String, Object> map=new HashMap<>();
        map.put("id", this.getId());
        map.put("cert_no", this.getCert_no());
        map.put("lictypeid", this.getLictypeid());
        map.put("pageindex", this.getPageindex());
        map.put("createtime", this.getCreatetime());
        map.put("exectime", this.getExectime());
        map.put("filepath", this.getFilepath());
        map.put("result", this.getResult());
        map.put("sealinfo", this.getSealinfo());
        return map;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Serializable id) {
        this.id = (Integer) id;
    }

    public Serializable getPrimaryKey() {
        return id;
        // return new Cloud_sign_licensePK(id, id2); 用于复合主键，请手动创建内部静态类
    }

    public void setPrimaryKey(Serializable key) {
        this.id = (Integer)key;

        //Cloud_sign_licensePK pk = (Cloud_sign_licensePK) key; 用于复合主键
        //this.id = pk.getId();
        //this.id2 = pk.getId2();
    }

    /**
     * 创建行政复议签章实例对象
     * @param applyid
     * @param code
     * @param filepath 文书路径
     * @return
     */
    public Cloud_sign_license buildAdmreLicense(String applyid, String code, String filepath, String textOffsetX) {
        Cloud_sign_config configObj = new Cloud_sign_config().buildAdmreConfig(applyid);
        // 盖章对象字段, 区分大小写
        Map<String, Object> configMap = new HashMap<>(16);
        configMap.put("page", configObj.getPageindex());
        configMap.put("text", configObj.getPostext());
        configMap.put("positionType", configObj.getPostype());
        configMap.put("sealCode", configObj.getSealcode());
        configMap.put("textOffsetY", "-21");
        configMap.put("textOffsetX", textOffsetX);
        Cloud_sign_license licenseObj = Cloud_sign_license.builder()
                .cert_no(code).lictypeid(Tp_lictype.ADMRE).pageindex(1).createtime(new Date()).filepath(filepath)
                .sealinfo("[" + JSON.toJSONString(configMap) + "]")
                .build();
        return licenseObj;
    }

}
